Skip to content

SOLR-18479: Use destination consistently in v2 schema APIs - #5380

Draft
epugh wants to merge 10 commits into
apache:mainfrom
epugh:SOLR-18479-v2-destination
Draft

epugh wants to merge 10 commits into
apache:mainfrom
epugh:SOLR-18479-v2-destination

Conversation

@epugh

@epugh epugh commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

The v2 Schema API uses destination consistently for copy-field writes and reads. Per-source requests use destination objects with independent maxChars; bulk add/delete operations name one destination each, and destination filtering uses destination.fl. V1 retains dest, its existing bulk syntax, and its response format through explicit adapters.

This draft follows #4943 and should merge after it. GitHub's PR diff includes the parent until that work reaches main; the follow-up-only comparison shows the naming change separately. Rebase onto main after #4943 merges before marking this ready.

The change updates the request models, generated clients, Admin UI, reference guide, upgrade notes, and changelog. Compatibility coverage checks v1 scalar/array dest requests, v1 reads and filters, and the generated v2 bulk client.

Validation: 85 targeted core API, legacy schema, serialization, and browser tests passed. ./gradlew tidy and check -x test passed. The latter used a temporary source-scan exclusion for unrelated local .claude/worktrees/; repository build files are unchanged. The full test suite was not run.

Developed with OpenAI Codex assistance.

janhoy and others added 10 commits September 24, 2026 17:47
Fields, dynamic fields and field types each have PUT/DELETE routes in the v2
Schema API; copy-fields were the one resource left reachable only through
/schema/bulk. The routes had been sketched out and commented out, with a TODO
noting that copy-field rules have no name to address them by.

Address them by source field instead: PUT /schema/copyfields/{sourceField}
takes a destinations list in the body, and DELETE removes every rule with that
source unless 'destination' query parameters narrow the selection. Deleting a
source that has no rules answers 404 rather than silently succeeding.

The source-addressed shape means one request covers a 1:many fan-out, at the
cost of the path naming a set of rules rather than a single one. Enumerating
the destinations for an unqualified DELETE goes through
IndexSchema.getCopyFieldProperties so that glob rules are covered as well as
explicit ones.

The ref guide's v2 copy-field examples are updated to the new endpoints; they
previously showed a v1 keyed-object body POSTed to /schema, which that path
answers with a 405 since it only carries GET.
The underlying 'add-copy-field' operation is purely additive: registerCopyField
appends a rule without checking whether an identical one is already present, so
PUTting the same destinations twice left the source copied twice over at index
time. That breaks PUT's idempotency contract, and it also meant the body could
only ever state the rules being added rather than the rules the caller wanted.

Clear the source's existing rules as part of the same SchemaManager operation
list, so the destinations in the body become the complete set for that source.
Applying both operations as a unit keeps the change transactional: a rejected
replacement leaves the previous rules in place.

Renamed the endpoint method to upsertCopyFields, since 'add' no longer describes
what it does.  Adding a destination while keeping the others now means either
listing them all, or using add-copy-field through the bulk endpoint, which still
only appends; the ref guide spells out both, along with the duplicate hazard of
the additive operation.
Rounds out /schema/copyfields/{sourceField} so the whole resource is addressed
through the path rather than partly through query parameters:

  GET    /copyfields/{source}                 the source's rules
  PUT    /copyfields/{source}                 set the complete destination list
  POST   /copyfields/{source}                 append destinations
  DELETE /copyfields/{source}                 remove all of the source's rules
  DELETE /copyfields/{source}/{destinations}  remove the named ones

The 'destination' query parameter is gone; a trailing path segment names the
destinations instead, several at a time as a comma-separated list. Splitting
goes through StrUtils.splitSmart so a separator inside quotes or behind a
backslash does not split; it does not trim, so surrounding whitespace (which can
only arrive percent-encoded) is dropped separately.

POST appends without disturbing the rules already in place, which PUT cannot do
without a read-modify-write, and which therefore avoids losing one of two
concurrent appends. Destinations the source already copies to are skipped rather
than appended a second time, so a retried POST is harmless -- worth having for a
caller that timed out without learning whether its first attempt landed.

GET by source overlaps the existing source.fl query parameter on /copyfields,
but reads the resource at the path the write verbs use, so the ref guide leads
with it and presents source.fl as the alternative for filtering by destination
or by several sources at once.
The replace and append operations worked out which rules to remove or skip in
the resource method, before handing SchemaManager a fixed list of operations.
That read happens outside the schema update lock, while doOperations takes the
lock, refreshes the schema and replays the operations on every retry. The list
could therefore be stale precisely when it mattered: a concurrently added
destination survived a replace, and a retry triggered by another node's change
could fail with "Copy field directive not found" for a rule that had since been
removed.

Move the diffing into two internal-only operations, upsert-copy-field and
append-copy-field, alongside the existing internal upsert-field. They inspect
managedIndexSchema, which doOperations refreshes under the lock, so each attempt
diffs against the rules actually in effect. Append builds a fresh operation
rather than narrowing the caller's, so a retry does not inherit the previous
attempt's filtering.

Deleting every rule for a source now goes through the same path, by replacing
its rules with none; the remaining out-of-lock read is only to report 404 for a
source that has no rules at all.

Also from review:
 - A path segment naming no destinations, e.g. /copyfields/src/,,, answered 404
   claiming the source had no rules, when the request was simply malformed and
   the source may well have rules. It is now a 400.
 - A request body whose 'source' contradicts the path was silently overwritten;
   it is now rejected.
 - Documented that a PUT with an empty destinations list clears the source, and
   that a GET for a source with no rules returns an empty list rather than 404.
   The test setup uses the former to reset state, which no longer needs to
   swallow a 404.
# Conflicts:
#	solr/solr-ref-guide/modules/indexing-guide/pages/schema-api.adoc
@epugh

epugh commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

i was worried we would have too much churn in #4943...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

admin-ui cat:api cat:schema documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants